import formatTime from '../../utils/formatTime.js'
Page({
  data: {
    blog: {},
    commentList: [],
    blogId: ''
  },
  onLoad(options) {
    this.data.blogId = options.blogId
    this.getBlogDetail()
  },

  getBlogDetail() {
    wx.showLoading({
      title: '加载中...',
      mask: true
    })
    wx.cloud.callFunction({
      name: 'blog',
      data: {
        $url: 'detail',
        blogId: this.data.blogId
      }
    }).then(res => {
      // 格式化时间
      let commentList = res.result.commentList.data
      for (let i = 0; i < commentList.length; i++) {
        commentList[i].createTime = formatTime(new Date(commentList[i].createTime))
      }

      this.setData({
        commentList,
        blog: res.result.detail[0]
      })
      wx.hideLoading()
    })
  },
  onShareAppMessage(e) {
    const blog = e.target.dataset.blog
    return {
      title: blog.content,
      path: `/pages/blog-comment/blog-comment?blogId=${blog._id}`,
      //  imageUrl: blog.img // 分享功能图片不支持云文件ID
    }
  }
})